package de.digisalt.dsnesds.editors.projectmeta.pages;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.IOperationHistory;
import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.core.commands.operations.ObjectUndoContext;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.PojoProperties;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchPartReference;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.operations.RedoActionHandler;
import org.eclipse.ui.operations.UndoActionHandler;
import org.eclipse.ui.operations.UndoRedoActionGroup;
import org.eclipse.wb.swt.ResourceManager;

import de.digisalt.dsnesds.core.model.mappings.projectmeta.CountrycodeMapping;
import de.digisalt.dsnesds.editors.projectmeta.SwitchableModifyListener;
import de.digisalt.dsnesds.editors.projectmeta.model.Model;
import de.digisalt.dsnesds.editors.projectmeta.operations.ChangeGameVersionOperation;

/**
 * @author flo The first (and up to now single) editor page for the project
 *         metadata editor.
 */
public class ProjectMetaFormPage extends FormPage
{
	/**
	 * the bindingcontext of this page (contains all databindings and references
	 * to their validation status)
	 */
	@SuppressWarnings("unused")
	private DataBindingContext				m_bindingContext;
	/**
	 * the textfield for the game shortname
	 */
	private Text											txtShortname;

	/**
	 * the pages data model to process on
	 */
	Model															model;
	/**
	 * the version spinner
	 */
	private Text											txtGamename;
	private Spinner										spinnerVersion;
	private Label											lblCountrycode;
	private Label											lblLicensee;
	private Combo											cmbCountrycode;
	private Combo											cmbLicensee;
	private Combo											cmbTiming;
	private Combo											cmbAddressing;
	private Combo											cmbCarttype;
	private Combo											cmbRomsize;
	private Combo											cmbRamsize;
	private Label											lblGameTitle;
	private FormEditor								editor;
	private SwitchableModifyListener	versionListener;
	private IOperationHistory					operationHistory;
	private IUndoContext							undoContext;
	private UndoRedoActionGroup				undoRedoActionGroup;

	/**
	 * Create the form page. Only used so that windowbuilder can create that clas
	 * private Combo cmbCountry; /** Create the form page. Only used so that
	 * windowbuilder can create that class
	 * 
	 * @param id
	 *          the id of the page
	 * @param title
	 *          the title to be displayed on the pages selectable tab
	 */
	public ProjectMetaFormPage(final String id, final String title)
	{
		super(id, title);
	}

	/**
	 * Create the form page.
	 * 
	 * @param editor
	 *          the editor the page belongs to
	 * @param id
	 *          the id of the page
	 * @param title
	 *          the title to be displayed in the editors tab
	 * @param model
	 *          the editor model to process on
	 * @wbp.parser.constructor
	 * @wbp.eval.method.parameter id "Some id"
	 * @wbp.eval.method.parameter title "Some title"
	 */
	public ProjectMetaFormPage(final FormEditor editor, final String id,
			final String title, Model model)
	{
		super(editor, id, title);
		this.editor = editor;
		this.model = model;
		operationHistory = editor.getSite().getWorkbenchWindow().getWorkbench()
				.getOperationSupport().getOperationHistory();
		undoContext = new ObjectUndoContext(this);
	}

	/**
	 * Create contents of the form.
	 * 
	 * @param managedForm
	 *          the base form every widget of this page will be added to
	 */
	@Override
	protected void createFormContent(final IManagedForm managedForm)
	{
		managedForm.getForm().setImage(
				ResourceManager.getPluginImage("de.digisalt.dsnesds.core",
						"graphics/icons/32/staticData.png"));
		FormToolkit toolkit = managedForm.getToolkit();
		ScrolledForm form = managedForm.getForm();
		form.setText("Project Metadata");
		Composite body = form.getBody();
		toolkit.decorateFormHeading(form.getForm());
		toolkit.paintBordersFor(body);
		managedForm.getForm().getBody().setLayout(new FillLayout(SWT.HORIZONTAL));

		SashForm sashForm = new SashForm(managedForm.getForm().getBody(), SWT.NONE);
		sashForm.setBounds(0, 0, 64, 64);
		managedForm.getToolkit().adapt(sashForm);
		managedForm.getToolkit().paintBordersFor(sashForm);

		Section sctnNewSection = managedForm.getToolkit().createSection(sashForm,
				Section.DESCRIPTION | Section.TITLE_BAR);
		sctnNewSection
				.setDescription("Project constants without any technical impact on the created game.");
		sctnNewSection.marginWidth = 5;
		sctnNewSection.marginHeight = 5;
		managedForm.getToolkit().paintBordersFor(sctnNewSection);
		sctnNewSection.setText("General Metadata");
		sctnNewSection.setExpanded(true);

		Composite composite = managedForm.getToolkit().createComposite(
				sctnNewSection, SWT.NONE);
		managedForm.getToolkit().paintBordersFor(composite);
		sctnNewSection.setClient(composite);
		composite.setLayout(new GridLayout(3, false));

		lblGameTitle = managedForm.getToolkit().createLabel(composite,
				"Game Title:", SWT.NONE);
		lblGameTitle.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false,
				2, 1));

		txtGamename = managedForm.getToolkit().createText(composite, "New Text",
				SWT.NONE);
		txtGamename.setText("");
		this.txtGamename.setTextLimit(20);
		txtGamename.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				1, 1));

		Label lblShortname = managedForm.getToolkit().createLabel(composite,
				"Shortname:", SWT.NONE);
		lblShortname.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false,
				2, 1));

		this.txtShortname = managedForm.getToolkit().createText(composite,
				"New Text", SWT.NONE);
		this.txtShortname.setText("");
		this.txtShortname.setTextLimit(4);
		this.txtShortname.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 1, 1));
		// a listener restricting this edit field to only 4 characters max
		this.txtShortname.addListener(SWT.Verify, new Listener()
		{
			@Override
			public void handleEvent(final Event event)
			{
				Point p = ProjectMetaFormPage.this.txtShortname.getSelection();
				int start = p.x;
				int end = p.y;
				int numberOfChars = ProjectMetaFormPage.this.txtShortname.getText()
						.length();
				int eventChars = event.text.length();
				int selectedCharsToDelete = end - start;
				int newNumberOfChars = numberOfChars - selectedCharsToDelete
						+ eventChars;
				if (newNumberOfChars > 4)
				{
					event.doit = false;
					return;
				}
			}
		});

		lblCountrycode = managedForm.getToolkit().createLabel(composite,
				"Countrycode:", SWT.NONE);
		lblCountrycode.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false,
				false, 2, 1));

		cmbCountrycode = new Combo(composite, SWT.READ_ONLY);
		cmbCountrycode.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
				false, 1, 1));
		cmbCountrycode.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 1, 1));
		cmbCountrycode.setItems(new CountrycodeMapping().getLabelSet());
		managedForm.getToolkit().adapt(cmbCountrycode);
		managedForm.getToolkit().paintBordersFor(cmbCountrycode);

		lblLicensee = managedForm.getToolkit().createLabel(composite, "Licensee:",
				SWT.NONE);
		lblLicensee.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false,
				2, 1));

		cmbLicensee = new Combo(composite, SWT.READ_ONLY);
		cmbLicensee.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				1, 1));
		managedForm.getToolkit().adapt(cmbLicensee);
		managedForm.getToolkit().paintBordersFor(cmbLicensee);
		cmbLicensee.setItems(new String[]
		{ "Absolute Entertainment", "Acclaim", "Accolade Europe Inc.",
				"Activision", "Ajinomoto", "American Sammy",
				"American Softworks Corp.", "Arcade Zone", "ASCII", "Ask Kodansha",
				"Asmik", "Athena", "Atlus", "Banalex", "BanDai America", "Banpresto",
				"Beam Software", "BEC", "Black Pearl", "Bullet-Proof Software",
				"Capcom", "Carrozzeria", "Character Soft",
				"Chris Gray Enterprises Inc.", "Chun Software", "COBRA Team",
				"Coconuts", "Culture Brain", "Data East", "DATAM-Polystar", "Digisalt",
				"Dynamic", "Electro Brain", "Electronic Arts", "Elite",
				"Empire Software", "Enix", "Epoch", "Falcom", "Field", "Game Village",
				"GameTek", "Gremlin Graphics", "Halken", "Hect", "Hi Tech Expressions",
				"Hiro", "Hori", "HOT-B", "Hudson Soft", "Human Entertainment", "I'Max",
				"Imagesoft", "Imagineer", "Infogrames", "INTEC Inc.", "Interplay",
				"Irem Japan", "Jaleco", "JVC", "K. Amusement", "Kaneco", "Kemco",
				"King A Wave", "KOEI", "Konami", "KSS", "Laser Beam",
				"LifeFitness Exertainment", "LJN Toys", "Loriciel", "Lozc",
				"LucasArts", "Magifact", "Masaya", "Maxis", "Mebio Software",
				"Meldac KAZe", "Micro World", "Micronet", "Microprose", "Mindscape",
				"Misawa", "Namco Ltd.", "Natsume", "Naxat", "NCS", "NHK", "Nichibutsu",
				"Nintendo", "Ocean", "Open System", "Origin", "Other", "Pack in Video",
				"Pal Soft", "Parker Brothers", "Pony Canyon", "POW", "Psygnosis Ltd.",
				"Quest", "Rage Software", "Renovation Products", "Ringler Studios",
				"Romstar", "S'Pal Inc.", "Sculptured Software", "Seika Corp.",
				"Seta Co. Ltd.", "Sigma", "Sofel", "Sony", "Sotsu Agency",
				"Spectrum Holobyte", "Squaresoft", "Starfish", "STORM", "Sunsoft",
				"System 3", "System Sacom Corp.", "T&E Software", "Taito", "Takara",
				"Tec Magik", "Technos", "Tecmo", "Teichio", "THQ Software", "Titus",
				"Toei Animation", "Toho", "Tokai Engineering",
				"Tokuma Shoten Intermedia", "Tomy", "Tonkin House",
				"Toshiba EMI System Vision", "Tradewest", "Triffix Entertainment",
				"Tsukuda Original", "U.S. Gold", "UBI Soft", "Varie",
				"Viacom New Media", "Video System", "Virgin Interactive Entertainment",
				"Visit Co. Ltd.", "Wolf Team", "Yanoman", "Zamuse", "Zoom" });

		Label lblVersion = managedForm.getToolkit().createLabel(composite,
				"Version:", SWT.NONE);
		lblVersion.addMouseListener(new MouseAdapter()
		{
			@Override
			public void mouseUp(MouseEvent arg0)
			{
				System.out.println("STOP");
			}
		});

		Label label = managedForm.getToolkit().createLabel(composite, "1.",
				SWT.NONE);
		label
				.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));

		this.spinnerVersion = new Spinner(composite, SWT.BORDER);
		this.spinnerVersion.setMaximum(255);
		this.spinnerVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
				false, 1, 1));
		managedForm.getToolkit().adapt(this.spinnerVersion);
		managedForm.getToolkit().paintBordersFor(this.spinnerVersion);

		Section sctnNewSection_1 = managedForm.getToolkit().createSection(sashForm,
				Section.DESCRIPTION | Section.TITLE_BAR);
		sctnNewSection_1.setDescription("Technical constants of the game");
		sctnNewSection_1.marginWidth = 5;
		sctnNewSection_1.marginHeight = 5;
		managedForm.getToolkit().paintBordersFor(sctnNewSection_1);
		sctnNewSection_1.setText("Technical Metadata");
		sctnNewSection_1.setExpanded(true);

		Composite composite_1 = managedForm.getToolkit().createComposite(
				sctnNewSection_1, SWT.NONE);
		managedForm.getToolkit().paintBordersFor(composite_1);
		sctnNewSection_1.setClient(composite_1);
		composite_1.setLayout(new GridLayout(2, false));

		Label lblRomTiming = managedForm.getToolkit().createLabel(composite_1,
				"Rom Timing:", SWT.NONE);
		lblRomTiming.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));

		cmbTiming = new Combo(composite_1, SWT.READ_ONLY);
		cmbTiming.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1,
				1));
		cmbTiming.setItems(new String[]
		{ "120 Nanoseconds (FASTROM)", "200 Nanoseconds (SLOWROM)" });
		managedForm.getToolkit().adapt(cmbTiming);
		managedForm.getToolkit().paintBordersFor(cmbTiming);

		Label lblAdressing = managedForm.getToolkit().createLabel(composite_1,
				"Addressing:", SWT.NONE);
		lblAdressing.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));

		cmbAddressing = new Combo(composite_1, SWT.READ_ONLY);
		cmbAddressing.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				1, 1));
		cmbAddressing.setItems(new String[]
		{ "LoROM", "HiROM" });
		managedForm.getToolkit().adapt(cmbAddressing);
		managedForm.getToolkit().paintBordersFor(cmbAddressing);

		Label lblCartridgeType = managedForm.getToolkit().createLabel(composite_1,
				"Cartridge Type:", SWT.NONE);
		lblCartridgeType.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));

		cmbCarttype = new Combo(composite_1, SWT.READ_ONLY);
		cmbCarttype.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				1, 1));
		cmbCarttype.setItems(new String[]
		{ "ROM", "ROM + RAM", "ROM + SRAM", "ROM + DSP", "ROM + RAM + DSP",
				"ROM + SRAM + DSP", "ROM + SuperFX", "ROM + RAM + SuperFX",
				"ROM + SRAM + SuperFX", "ROM + SRAM + SA-1" });
		managedForm.getToolkit().adapt(cmbCarttype);
		managedForm.getToolkit().paintBordersFor(cmbCarttype);

		Label lblRomSize = managedForm.getToolkit().createLabel(composite_1,
				"ROM Size:", SWT.NONE);
		lblRomSize.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false,
				1, 1));

		cmbRomsize = new Combo(composite_1, SWT.READ_ONLY);
		cmbRomsize.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1,
				1));
		cmbRomsize.setItems(new String[]
		{ "256 Kilobytes", "512 Kilobytes", "1 Megabyte", "2 Megabytes",
				"4 Megabytes" });
		managedForm.getToolkit().adapt(cmbRomsize);
		managedForm.getToolkit().paintBordersFor(cmbRomsize);

		Label lblRamSize = managedForm.getToolkit().createLabel(composite_1,
				"RAM Size:", SWT.NONE);
		lblRamSize.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false,
				1, 1));

		cmbRamsize = new Combo(composite_1, SWT.READ_ONLY);
		cmbRamsize.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1,
				1));
		cmbRamsize.setItems(new String[]
		{ "0 Kilobytes", "2 Kilobytes", "4 Kilobytes", "8 Kilobytes" });
		managedForm.getToolkit().adapt(cmbRamsize);
		managedForm.getToolkit().paintBordersFor(cmbRamsize);
		sashForm.setWeights(new int[]
		{ 1, 1 });

		// own custom methods:
		addListeners();
		// provide content and labelproviders for JFace Viewers
		prepareViewers();
		// init databindings
		this.m_bindingContext = initDataBindings();

		getEditorSite().getPage().addPartListener(
				new org.eclipse.ui.IPartListener2()
				{
					@Override
					public void partInputChanged(IWorkbenchPartReference partRef)
					{
					}

					@Override
					public void partVisible(IWorkbenchPartReference partRef)
					{
					}

					@Override
					public void partHidden(IWorkbenchPartReference partRef)
					{
					}

					@Override
					public void partOpened(IWorkbenchPartReference partRef)
					{
					}

					@Override
					public void partDeactivated(IWorkbenchPartReference partRef)
					{
						// lost focus
					}

					@Override
					public void partClosed(IWorkbenchPartReference partRef)
					{
					}

					@Override
					public void partBroughtToTop(IWorkbenchPartReference partRef)
					{
					}

					@Override
					public void partActivated(IWorkbenchPartReference partRef)
					{
						addUndoRedoHooks();
					}
				});
	}

	/**
	 * sets the inputs for the JFace viewers as well as content and label
	 * providers
	 */
	private void prepareViewers()
	{
		// TODO: add content and label providers if needed
	}

	/**
	 * a method adding all component listeners to the widgets and model objects
	 */
	private void addListeners()
	{
		addUndoRedoHooks();

		versionListener = new SwitchableModifyListener()
		{
			@Override
			public void doModifyText(ModifyEvent arg0)
			{
				ChangeGameVersionOperation operation = new ChangeGameVersionOperation(
						"Change Game Version", model, spinnerVersion.getSelection(),
						undoContext);
				try
				{
					operationHistory.execute(operation, null, null);
				}
				catch (ExecutionException e)
				{
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		};
		spinnerVersion.addModifyListener(versionListener);

		model.addPropertyChangeListener(new PropertyChangeListener()
		{

			@Override
			public void propertyChange(PropertyChangeEvent evt)
			{
				switch (evt.getPropertyName())
				{
				case "version":
				{
					versionListener.setActive(false);
					spinnerVersion.setSelection(((Integer) evt.getNewValue()).intValue());
					versionListener.setActive(true);
					break;
				}
				case "video":
				{
					break;
				}
				case "licensee":
				{
					break;
				}
				case "country":
				{
					break;
				}
				case "ramsize":
				{
					break;
				}
				case "addressing":
				{
					break;
				}
				case "romsize":
				{
					break;
				}
				case "carttype":
				{
					break;
				}
				case "timing":
				{
					break;
				}
				case "shortname":
				{
					break;
				}
				case "gamename":
				{
					break;
				}
				default:
				{
					break;
				}
				}
			}
		});
		// TODO: add more listeners if needed
	}

	/*
	 * This method enables the undo/redo hooks for the editor
	 */
	private void addUndoRedoHooks()
	{
		// TODO: no fucking idea why THIS doesn't work...
		undoRedoActionGroup = new UndoRedoActionGroup(this.getSite(), undoContext,
				true);
		// so I had to implement undo redo hooks like this:
		getEditorSite().getActionBars().setGlobalActionHandler(
				ActionFactory.UNDO.getId(),
				new UndoActionHandler(getSite(), undoContext));

		getEditorSite().getActionBars().setGlobalActionHandler(
				ActionFactory.REDO.getId(),
				new RedoActionHandler(getSite(), undoContext));
	}

	protected DataBindingContext initDataBindings()
	{
		DataBindingContext bindingContext = new DataBindingContext();
		//
		IObservableValue observeSelectionCmbCountry_1ObserveWidget = WidgetProperties
				.selection().observeDelayed(300, cmbCountrycode);
		IObservableValue countryModelObserveValue = PojoProperties.value("country")
				.observe(model);
		bindingContext.bindValue(observeSelectionCmbCountry_1ObserveWidget,
				countryModelObserveValue, null, null);
		//
		IObservableValue observeSelectionCmbLicenseeObserveWidget = WidgetProperties
				.selection().observeDelayed(300, cmbLicensee);
		IObservableValue licenseeModelObserveValue = PojoProperties.value(
				"licensee").observe(model);
		bindingContext.bindValue(observeSelectionCmbLicenseeObserveWidget,
				licenseeModelObserveValue, null, null);
		/*
		 * // IObservableValue observeSelectionSpinnerVersionObserveWidget =
		 * WidgetProperties .selection().observeDelayed(300, spinnerVersion);
		 * IObservableValue versionModelObserveValue =
		 * PojoProperties.value("version") .observe(model);
		 * bindingContext.bindValue(observeSelectionSpinnerVersionObserveWidget,
		 * versionModelObserveValue, null, null);
		 */
		//
		IObservableValue observeSelectionCmbTimingObserveWidget = WidgetProperties
				.selection().observeDelayed(300, cmbTiming);
		IObservableValue timingModelObserveValue = PojoProperties.value("timing")
				.observe(model);
		bindingContext.bindValue(observeSelectionCmbTimingObserveWidget,
				timingModelObserveValue, null, null);
		//
		IObservableValue observeSelectionCmbAddressingObserveWidget = WidgetProperties
				.selection().observeDelayed(300, cmbAddressing);
		IObservableValue addressingModelObserveValue = PojoProperties.value(
				"addressing").observe(model);
		bindingContext.bindValue(observeSelectionCmbAddressingObserveWidget,
				addressingModelObserveValue, null, null);
		//
		IObservableValue observeSelectionCmbCarttypeObserveWidget = WidgetProperties
				.selection().observeDelayed(300, cmbCarttype);
		IObservableValue carttypeModelObserveValue = PojoProperties.value(
				"carttype").observe(model);
		bindingContext.bindValue(observeSelectionCmbCarttypeObserveWidget,
				carttypeModelObserveValue, null, null);
		//
		IObservableValue observeSelectionCmbRomsizeObserveWidget = WidgetProperties
				.selection().observeDelayed(300, cmbRomsize);
		IObservableValue romsizeModelObserveValue = PojoProperties.value("romsize")
				.observe(model);
		bindingContext.bindValue(observeSelectionCmbRomsizeObserveWidget,
				romsizeModelObserveValue, null, null);
		//
		IObservableValue observeSelectionCmbRamsizeObserveWidget = WidgetProperties
				.selection().observeDelayed(300, cmbRamsize);
		IObservableValue ramsizeModelObserveValue = PojoProperties.value("ramsize")
				.observe(model);
		bindingContext.bindValue(observeSelectionCmbRamsizeObserveWidget,
				ramsizeModelObserveValue, null, null);
		//
		IObservableValue observeTextTxtShortnameObserveWidget = WidgetProperties
				.text(SWT.Modify).observeDelayed(300, txtShortname);
		IObservableValue shortNameModelObserveValue = PojoProperties.value(
				"shortName").observe(model);
		bindingContext.bindValue(observeTextTxtShortnameObserveWidget,
				shortNameModelObserveValue, null, null);
		//
		IObservableValue observeTextTxtTxtgamenameObserveWidget = WidgetProperties
				.text(SWT.Modify).observeDelayed(300, txtGamename);
		IObservableValue gameNameModelObserveValue = PojoProperties.value(
				"gameName").observe(model);
		bindingContext.bindValue(observeTextTxtTxtgamenameObserveWidget,
				gameNameModelObserveValue, null, null);
		//
		return bindingContext;
	}
}
